﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataRecv.models.tail
{
    
    /// <summary>
    /// 杰瑞图片尾部信息结构体
    /// </summary>
    public class JariTail
    {
        /// <summary>
        /// 杰瑞尾部图片信息长度
        /// </summary>
        public const int JARIINFOLENGTH = 165;
        public JariTail()
        {
            m_Info1 = "";
            m_Info2 = "";
            m_Info3 = "";
            m_Info4 = "";
            m_Info5 = "";
            m_Info6 = "";
            m_Info7 = "";
            m_Info8 = "";
            m_Info9 = "";
            m_Info10 = "";
            m_Info11 = "";
            m_Info12 = "";
            m_Info13 = "";
            m_Info14 = "";
            m_Info15 = "";
            m_Info16 = "";
            m_Info17 = "";
            m_Info18 = "";
            m_Info19 = "";
            m_Info20 = "";
            m_Info21 = "";
            m_Info22 = "";
            m_Info23 = "";
            m_Info24 = "";
        }
        /// <summary>
        /// 预留，长度19
        /// </summary>
        public string m_Info1;
        /// <summary>
        /// 图片序号，长度1
        /// 值0-2
        /// </summary>
        public string m_Info2;
        /// <summary>
        /// 旋转标识，长度1
        /// 0---不旋转
        /// 1---旋转
        /// </summary>
        public string m_Info3;
        /// <summary>
        /// 车牌号码，长度16
        /// </summary>
        public string m_Info4;
        /// <summary>
        /// 车牌颜色，长度1
        /// 0---蓝色
        /// 1---黄色
        /// 2---白色
        /// 3---黑色
        /// </summary>
        public string m_Info5;
        /// <summary>
        /// 车牌类型,长度1
        /// 0---标准民用与军车车牌
        /// 1---02 式民用车牌
        /// 2---武警车牌
        /// 3---警车车牌
        /// 4---民用车双行尾牌
        /// </summary>
        public string m_Info6;
        /// <summary>
        /// 车身颜色，长度1
        /// 0---其他
        ///1---白色
        ///2---银色
        ///3---灰色
        ///4---黑色
        ///5---红色
        ///6---深蓝
        ///7---蓝色
        ///8---黄色
        ///9---绿色
        ///10---棕色
        ///11---粉色
        ///12---紫色
        /// </summary>
        public string m_Info7;
        /// <summary>
        /// 车身颜色深浅，长度1
        /// 0---深色
        /// 1---浅色
        /// </summary>
        public string m_Info8;
        /// <summary>
        /// 车辆类型，长度1
        /// 0---其他
        /// 1---小型车辆
        /// 2---大型车辆
        /// </summary>
        public string m_Info9;
        /// <summary>
        /// 违法记录类型，长度1
        /// 杰瑞规定：
        /// 0---卡口
        /// 1---逆行
        /// 2---超速
        /// 3---闯红灯
        /// 4---压线(协议新增)
        /// 5---不按导线行驶(协议新增)
        /// 海康规定：
        /// 0-正常：1-低速，2-超速，3-逆行，4-闯红灯，5-压车道线，6-不按导向 
        /// </summary>
        public string m_Info10;
        /// <summary>
        /// 车长，长度1
        /// 精确到0.1 米
        /// </summary>
        public string m_Info11;
        /// <summary>
        /// 路口名称，长度32
        /// </summary>
        public string m_Info12;
        /// <summary>
        /// 拍摄车道，长度1
        /// 取值范围1-4 和摄像机接线有关
        /// </summary>
        public string m_Info13;
        /// <summary>
        /// 识别位置，长度48
        /// 识别位置:一个车道对应
        ///两个识别区域共16 个字
        ///节；每个识别区域8 个字
        ///节，分别存储“Left ，
        ///Right，Top，Bottom”值
        ///（每个值2 个字节）；
        ///77+0~77+15 为第一个车
        ///道，依次类推；
        /// </summary>
        public string m_Info14;
        /// <summary>
        /// 车道,长度1，在抓拍当前车道时，其余车道过车信息
        /// </summary>
        public string m_Info15;
        /// <summary>
        /// 毫秒，长度2
        /// </summary>
        public string m_Info16;
        /// <summary>
        /// 违法地点，长度2，地点代码
        /// </summary>
        public string m_Info17;
        /// <summary>
        /// 违法时间，长度19，YYYY-MM-DD HH:MM:SS
        /// </summary>
        public string m_Info18;
        /// <summary>
        /// 行驶方向，长度1，
        /// 1- 由东向西
        /// 2- 由南向北
        /// 3- 由西向东
        /// 4- 由北向南
        /// </summary>
        public string m_Info19;
        /// <summary>
        /// 车道，长度5
        /// 实际车道标识，取值如下：车道1、车道2、车道3
        /// </summary>
        public string m_Info20;
        /// <summary>
        /// 限速，长度3，KM/h
        /// </summary>
        public string m_Info21;
        /// <summary>
        /// 车速，长度3，KM/h
        /// </summary>
        public string m_Info22;
        /// <summary>
        /// ID号，长度3,0-999
        /// </summary>
        public string m_Info23;
        /// <summary>
        /// 摄像机类型，长度1
        /// 0---普清
        /// 1---JR200 万高清
        /// 2---JR500 万高清
        /// 3---JR200 万高清旋转
        /// 6---JH200 万高清
        /// 7---JH500 万高清
        /// 9---车辆牌照
        /// </summary>
        public string m_Info24;


        /// <summary>
        /// 生成杰瑞尾部图片byte[]
        /// </summary>
        /// <param name="info">尾部信息结构体</param>
        /// <returns>尾部信息byte[]</returns>
        public byte[] MakeTail()
        {
            byte[] tail = null;
            try
            {
                tail = new byte[JARIINFOLENGTH];
                Encoding.Default.GetBytes(m_Info1, 0, m_Info1.Length, tail, 0);
                //Encoding.Default.GetBytes(m_Info2, 0, m_Info2.Length, tail, 19);//睢宁不需要
                //Encoding.Default.GetBytes(m_Info3, 0, m_Info3.Length, tail, 20);//睢宁不需要
                Encoding.Default.GetBytes(m_Info4, 0, m_Info4.Length, tail, 21);
                Encoding.Default.GetBytes(m_Info5, 0, m_Info5.Length, tail, 37);
                //Encoding.Default.GetBytes(m_Info6, 0, m_Info6.Length, tail, 38);//睢宁不需要
                //Encoding.Default.GetBytes(m_Info7, 0, m_Info7.Length, tail, 39);//睢宁不需要
                //Encoding.Default.GetBytes(m_Info8, 0, m_Info8.Length, tail, 40);//睢宁不需要
                //Encoding.Default.GetBytes(m_Info9, 0, m_Info9.Length, tail, 41);//睢宁不需要
                Encoding.Default.GetBytes(m_Info10, 0, m_Info10.Length, tail, 42);//睢宁不需要
                //Encoding.Default.GetBytes(m_Info11, 0, m_Info11.Length, tail, 43);//睢宁不需要
                Encoding.Default.GetBytes(m_Info12, 0, m_Info12.Length, tail, 44);
                //Encoding.Default.GetBytes(m_Info13, 0, m_Info13.Length, tail, 76);//睢宁不需要
                //Encoding.Default.GetBytes(m_Info14, 0, m_Info14.Length, tail, 77);//睢宁不需要
                //Encoding.Default.GetBytes(m_Info15, 0, m_Info15.Length, tail, 125);//睢宁不需要
                //Encoding.Default.GetBytes(m_Info16, 0, m_Info16.Length, tail, 126);//睢宁不需要
                Encoding.Default.GetBytes(m_Info17, 0, m_Info17.Length, tail, 128);
                Encoding.Default.GetBytes(m_Info18, 0, m_Info18.Length, tail, 130);
                Encoding.Default.GetBytes(m_Info19, 0, m_Info19.Length, tail, 149);//睢宁不需要
                Encoding.Default.GetBytes(m_Info20, 0, m_Info20.Length, tail, 150);//睢宁不需要
                Encoding.Default.GetBytes(m_Info21, 0, m_Info21.Length, tail, 155);//睢宁不需要
                Encoding.Default.GetBytes(m_Info22, 0, m_Info22.Length, tail, 158);//睢宁不需要
                //Encoding.Default.GetBytes(m_Info23, 0, m_Info23.Length, tail, 161);//协议只有3位，这里是5位，暂时不做
                //Encoding.Default.GetBytes(m_Info24, 0, m_Info24.Length, tail, 164);//睢宁不需要
            }
            catch
            {
                tail = null;
            }
            return tail;
        }

        /// <summary>
        /// 添加尾部信息到图片
        /// </summary>
        /// <param name="info">尾部信息</param>
        /// <param name="pic">图片byte[]</param>
        /// <returns>带尾部信息的图片byte[]</returns>
        public byte[] AddTailToPic(byte[] pic)
        {
            byte[] ans = null;
            try
            {
                byte[] tail = MakeTail();
                if ((tail != null) && (pic != null))
                {
                    int tailLength = tail.Length;
                    int picLength = pic.Length;
                    ans = new byte[tailLength + picLength];
                    Array.Copy(pic, 0, ans, 0, picLength);
                    Array.Copy(tail, 0, ans, picLength, tailLength);
                }
            }
            catch
            {
                ans = pic;
            }
            return ans;
        }
    }
}
